from django.db import models
from tools import mysqlHelper
from tools import mssqlHelper

class Ratings(models.Model):
    # UserID::MovieID::Rating::Timestamp
    UserID = models.CharField(max_length=30)
    MovieID = models.CharField(max_length=30)
    Rating = models.CharField(max_length=30)
    Timestamp = models.CharField(max_length=30)
    def __unicode__(self):
        return u'%s %s %s' % (self.UserID, self.MovieID,self.Rating)

class Users(models.Model):
    # UserID::Gender::Age::Occupation::Zip-code
    UserID = models.CharField(max_length=30)
    Gender = models.CharField(max_length=30)
    Age = models.CharField(max_length=30)
    Occupation = models.CharField(max_length=30)
    Zipcode = models.CharField(max_length=30)
    def __unicode__(self):
        return u'%s %s %s' % (self.UserID, self.Gender,self.Age)

class Movies(models.Model):
    # MovieID::Title::Genres
    MovieID = models.CharField(max_length=30)
    Title = models.CharField(max_length=150)
    Genres = models.CharField(max_length=150)
    def __unicode__(self):
        return u'%s %s %s' % (self.MovieID, self.Title,self.Genres)

class myrec_user_item(models.Model):
    def get_user_item(self):
        sql ='''
        SELECT TOP 10 userid,num_iid,cnt FROM logdb.dbo.tmp_ldwu_20150127_rec
        '''
        fetchall= mssqlHelper.getdata(sql)
        return fetchall